package com.songlanyun.modules.opus.controller.admin;

import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.exception.BbsException;
import com.songlanyun.modules.opus.entity.OpusThemeSystem;
import com.songlanyun.modules.opus.model.dto.OpusThemeSystemDTO;
import com.songlanyun.modules.opus.service.OpusThemeSystemService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 作品主题表
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2021-01-13 16:35:02
 */
@RestController
@RequestMapping("admin/opus/theme")
public class OpusThemeSystemAdminController extends AbstractController {
    @Autowired
    private OpusThemeSystemService opusThemeSystemService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("opus:systembbstheme:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = opusThemeSystemService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 按id查询作品主题
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("opus:systembbstheme:info")
    public R info(@PathVariable("id") Integer id) {
        OpusThemeSystem bbsTheme = opusThemeSystemService.loadById(id, false);
        return R.ok().put("data", bbsTheme);
    }

    /**
     * 创建作品主题
     */
    @SysLog("创建作品主题")
    @PostMapping("/add")
    //@RequiresPermissions("opus:systembbstheme:save")
    public R add(@RequestBody OpusThemeSystemDTO dto) {
        ValidatorUtils.validateEntity(dto);
        OpusThemeSystem bbsTheme = opusThemeSystemService.add(dto);
        return R.ok().put("data", bbsTheme);
    }

    /**
     * 修改作品主题
     */
    @SysLog("修改作品主题")
    @PutMapping("/edit")
    //@RequiresPermissions("opus:systembbstheme:update")
    public R edit(@RequestBody OpusThemeSystemDTO dto) {
        ValidatorUtils.validateEntity(dto);
        OpusThemeSystem bbsTheme = opusThemeSystemService.edit(dto);
        return R.ok().put("data", bbsTheme);
    }

    /**
     * 显示
     */
    @SysLog("作品主题显示")
    @PostMapping("/open")
    //@RequiresPermissions("opus:systembbstheme:save")
    public R open(@RequestBody OpusThemeSystemDTO dto) {
        if (dto.getId() == null || dto.getOpen() == null) {
            throw new RRException(BbsException.PARAMETER_IS_NOT_COMPLETE);
        }
        opusThemeSystemService.open(dto);
        return R.ok();
    }

    /**
     * 置顶
     */
    @SysLog("作品主题置顶")
    @PostMapping("/stick")
    //@RequiresPermissions("opus:systembbstheme:save")
    public R stick(@RequestBody OpusThemeSystemDTO dto) {
        if (dto.getId() == null || dto.getStick() == null) {
            throw new RRException(BbsException.PARAMETER_IS_NOT_COMPLETE);
        }
        opusThemeSystemService.stick(dto);
        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("删除作品主题")
    @DeleteMapping("/delete/{id}")
    //@RequiresPermissions("opus:systembbstheme:delete")
    public R delete(@PathVariable("id") Integer id) {

        opusThemeSystemService.deleteById(id);
        return R.ok();
    }

}
